﻿using System;

namespace Calendar
{
    /// <summary>
    /// 输出当月日历
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            string s = "    ";
            Console.WriteLine("输入年份：");
            int nYear = int.Parse(Console.ReadLine());
            Console.WriteLine("输入月份：");
            int nMonth = int.Parse(Console.ReadLine());
            DateTime day1 = new DateTime(nYear, nMonth, 1);
            Console.WriteLine("{0}年{1}月", day1.Year, day1.Month);
            Console.WriteLine("日  一  二  三  四  五  六");
            int week1 = (int)day1.DayOfWeek; //获取当月1号的星期数   
            int lastday = day1.AddMonths(1).AddDays(-1).Day; //获取当月的最后一天  
            for (int i = 0; i < week1; i++)
                Console.Write(s);//换行输出

            for (int i = 1; i <= lastday; i++)
            {
                Console.Write("{0:00}  ", i);//个位数日期按01形式输出  
                if ((i + week1) % 7 == 0)
                    Console.WriteLine();
            }
            Console.WriteLine();
            Console.Write("Press any key to continue . . . ");
            Console.ReadKey(true);
        }
    }
}
